#pragma once
#include "interfaces.h"
#include "ALEstd.h"
#include "Geometry.h"
#include <LuaPlus.h>

class LuaStateManager : public IScriptManager
{
	static LuaStateManager* s_pSingleton;
	LuaPlus::LuaState* m_pLuaState;
	std::string m_lastError;

public:
	static bool Create();
	static void Destroy();
	static LuaStateManager* Get() { return s_pSingleton; }

	virtual bool VInit() override;
	virtual void VExecuteFile(const char* resource) override;
	virtual void VExecuteString(const char* str) override;

	LuaPlus::LuaObject GetGlobalVars();
	LuaPlus::LuaState* GetLuaState() const;

	LuaPlus::LuaObject CreatePath(const char* pathString, bool toIgnoreLastElement = false);
	void ConvertVec3ToTable(const Vec3& vec, LuaPlus::LuaObject& outLuaTable) const;
	void ConvertTableToVec3(const LuaPlus::LuaObject& luaTable, Vec3& outVec3) const;

private:
	void SetError(int errorNum);
	void ClearStack();

	explicit LuaStateManager();
	virtual ~LuaStateManager();
};